//
//  XJSCTopicsCell.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/6/26.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJSCTopicsCell.h"


@interface XJSCTopicsCell()
@property (weak, nonatomic) IBOutlet UIImageView *iconIv; //头像
@property (weak, nonatomic) IBOutlet UILabel *nameLb;//姓名
@property (weak, nonatomic) IBOutlet UILabel *timeLb;//时间
@property (weak, nonatomic) IBOutlet UILabel *biaoTiLb;//标题
@property (weak, nonatomic) IBOutlet UILabel *neiRongLb; //内容


@end

@implementation XJSCTopicsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
//    [self.selBtn setImage:[UIImage imageNamed:@"selected_off"] forState:(UIControlStateNormal)];
//    [self.selBtn setImage:[UIImage imageNamed:@"selected_on"] forState:(UIControlStateHighlighted)];
    
    self.selBtn.hidden = YES; //默认隐藏 点击编辑按钮的时候才显示。
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)setModel:(XJShouCangTopicsModel *)model {
    
    UIImage *placeholdeImg = [UIImage imageNamed:@"default_head"];
    
    [self.iconIv sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:placeholdeImg];

    
    CGFloat iconW = self.iconIv.bounds.size.width / 2.0;
    self.iconIv.layer.masksToBounds = YES;
    self.iconIv.layer.cornerRadius = iconW;
    
    self.nameLb.text = model.publish_name;
    self.timeLb.text = [self stringFromTimeStamp:[NSString stringWithFormat:@"%@",model.create_time]];
    
    self.biaoTiLb.text = model.title;
    self.neiRongLb.text = model.content;
    
    //选中按钮的选中状态
    self.selBtn.selected = model.isChecked;
}


// 时间戳转时间
- (NSString *)stringFromTimeStamp:(NSString *)stampStr {
    
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    [fmt setDateStyle:(NSDateFormatterMediumStyle)];
    [fmt setTimeStyle:(NSDateFormatterShortStyle)];
    fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[stampStr doubleValue] / 1000.0];
    NSString *dateStr = [fmt stringFromDate:date];
    
    return dateStr;
}
@end
